﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class DislpayOrdersByDate : EmployeePage
{
    #region Events
    protected void Page_Load(object sender, EventArgs e)
    {
        CheckCredentials();
        _imgConfirm.Visible = IsLoggedIn;
        if (!IsPostBack)
        {
            _calander.SelectedDate = DateTime.Today;
            ListAllOrders(_calander.SelectedDate);
        }
    }

    protected void _dtgAllorders_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        System.Collections.Specialized.OrderedDictionary keys =
            (System.Collections.Specialized.OrderedDictionary)_dtgAllorders.DataKeys[e.RowIndex].Values;

        int companyId = Convert.ToInt32(keys["CompanyId"]);
        int orderId = Convert.ToInt32(keys["OrderId"]);
        Facade.Employee().DeleteOrder(companyId, orderId);

        ListAllOrders(_calander.SelectedDate);
    }

    protected void _calander_SelectedDateChanged(object source, DevExpress.Web.ASPxDataControls.SelectedDateChangedEventArgs e)
    {
        if (_calander.SelectedDate.CompareTo(DateTime.MinValue) != 0)
        {
            ListAllOrders(_calander.SelectedDate);
        }
    }
    #endregion

    #region Link Transfer
    protected void _ibmHomePage_Click(object sender, ImageClickEventArgs e)
    {
        if (!IsPostBack || (e.X != 0 && e.Y != 0))
        {
            Server.Transfer("~/Company.aspx",true);
        }
    }
    protected void _lbtnCompanyBooking_Click(object sender, EventArgs e)
    {
        Server.Transfer("~/CompanyBooking.aspx", true);
    }
	protected void _lbtnCompanyBooking1_Click(object sender, EventArgs e)
	{
		Server.Transfer("~/CompanyBooking.aspx", true);
    }
    #endregion

    #region Private List Methods
    private void ListAllOrders(DateTime date)
    {
        _dtgAllorders.DataSource = Facade.Employee().GetOrdersByDate(
            GetCompanyIdFromCookie(),
            date);
        _dtgAllorders.DataBind();
    }
    #endregion
    protected void _lbtnConfig_Click(object sender, EventArgs e)
    {
        Server.Transfer("~/Config.aspx", true);
    }
}
